
package bsc.war.form;

/**
 *
 * @author castrosalazar
 */


import bsc.ejb.entity.SRMTopic;
import bsc.ejb.entity.TopicScoreView;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class EditSRMTopic extends AbstractController
{

    public EditSRMTopic() {
    }

    @Override
    protected ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            Long idSRMTopic = request.getParameter("srmtopic") != null && NumberUtils.isNumber(request.getParameter("srmtopic")) ? Long.parseLong(request.getParameter("srmtopic")) : null;

            SRMTopic SRMTopic = delegate.findSRMTopic(idSRMTopic);
            TopicScoreView topicScoreView = delegate.findTopicScoreView(SRMTopic.getTopic(), SRMTopic.getSRM().getScoreView());

            /*
                from SRMTopic u can get:
                Topic topic
                SRM SRM
                private Double expectedTime;
                private String agreement;
                private String responsable;
                private String description;
                private String deal;
             *
                from TopicScoreView u can get:
                private Topic topic;
                private ScoreView scoreView;
                private Type type{DELAYED,IN_PROCESS,COMPLETED}
             *
                a select for enums should be like this:
                 <select name="type">
                 <option value="DELAYED">con retraso</option>
                 <option value="IN_PROCESS">en proceso</option>
                 <option value="COMPLETED">completado</option>
                 </select>
             */

            request.setAttribute("SRMTopic",SRMTopic);
            request.setAttribute("topicScoreView",topicScoreView);

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Caught exception: ", e);
        }
        return new ModelAndView("editSRMTopic");
    }
}
